package com.ruoyi.web.controller.emergency;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.emergency.dto.EmergencyDeviceDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.emergency.domain.EmergencyDevice;
import com.ruoyi.emergency.service.IEmergencyDeviceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应急救援物资Controller
 * 
 * @author hcc
 * @date 2024-11-17
 */
@RestController
@RequestMapping("/control/emergencyDevice")
public class EmergencyDeviceController extends BaseController
{
    @Autowired
    private IEmergencyDeviceService emergencyDeviceService;

    /**
     * 查询应急救援物资列表
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyDevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmergencyDevice emergencyDevice)
    {
        startPage();
        List<EmergencyDevice> list = emergencyDeviceService.selectEmergencyDeviceList(emergencyDevice);
        return getDataTable(list);
    }

    /**
     * 查询应急救援物资列表
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyDevice:list')")
    @GetMapping("/getDeviceList")
    public TableDataInfo getDeviceList(EmergencyDevice emergencyDevice)
    {
        startPage();
        PageInfo<EmergencyDeviceDto> list = emergencyDeviceService.getDeviceList(emergencyDevice);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list.getList());
        rspData.setTotal(list.getTotal());
        return rspData;
    }
    /**
     * 导出应急救援物资列表
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyDevice:export')")
    @Log(title = "应急救援物资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmergencyDevice emergencyDevice)
    {
        List<EmergencyDevice> list = emergencyDeviceService.selectEmergencyDeviceList(emergencyDevice);
        ExcelUtil<EmergencyDevice> util = new ExcelUtil<EmergencyDevice>(EmergencyDevice.class);
        util.exportExcel(response, list, "应急救援物资数据");
    }

    /**
     * 获取应急救援物资详细信息
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyDevice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(emergencyDeviceService.selectEmergencyDeviceById(id));
    }

    /**
     * 新增应急救援物资
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyDevice:add')")
    @Log(title = "应急救援物资", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmergencyDevice emergencyDevice)
    {
        return toAjax(emergencyDeviceService.insertEmergencyDevice(emergencyDevice));
    }

    /**
     * 修改应急救援物资
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyDevice:edit')")
    @Log(title = "应急救援物资", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmergencyDevice emergencyDevice)
    {
        return toAjax(emergencyDeviceService.updateEmergencyDevice(emergencyDevice));
    }

    /**
     * 删除应急救援物资
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyDevice:remove')")
    @Log(title = "应急救援物资", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emergencyDeviceService.deleteEmergencyDeviceByIds(ids));
    }
}
